import tensorflow as tf

if __name__ == '__main__':
    print(tf.__version__)
    gpus = tf.config.list_physical_devices('GPU')
    print(gpus)
    gpus = tf.config.experimental.list_physical_devices('GPU')
    print(gpus)
    
    if gpus:
        try:
            for gpu in gpus:
                tf.config.experimental.set_memory_growth(gpu, True)
            print("GPU 加速已启用")
        except RuntimeError as e:
            print(e)